//
// C++ Interface: parser
//
// Description: 
//
//
// Author: j3drek <andrew_lz@poczta.fm>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef PARSER_H
#define PARSER_H

#include <QtGui>
#include <QString>

class QDialogButtonBox;
class QFile;
class QHttp;
class QHttpResponseHeader;
class QLabel;
class QLineEdit;
class QProgressDialog;
class QPushButton;

/**
	@author j3drek <andrew_lz@poczta.fm>
*/

class Parser : public QMainWindow
{
    Q_OBJECT
public:
    QHttp *http;
    QFile *file;
    QString currentFile;

public:
    QProgressBar *progress;
    QLineEdit    *editCharacter;
    QPushButton  *buttonSearch;
    QTreeWidget  *listView;

public:
    Parser(QWidget * parent = 0);
    int getData(const QString & cname);
    void clean();
    int htmlParse();
    void addKey(const QString & key, const QString & value);
    void addLabel(const QString & lebel);
    QString fileName(const QString & cname);
    ~Parser();
    int tagit;
    bool charMode, parsingDone;
    int httpGetId;
    bool isDone;

    static void htmlEnumeratorProc(void *data, const QString &tag, const QString &context, int startpos) ;

    static int toFile(const QString & fileName, const QString &data );
    static QString tmpFile(const QString & fileName);
    static QString translate(const QString & text);
    bool appQuery(const QString&text);
    void appMsg(const QString&text, const QString&caption = QString::null);

public slots:
     void on_buttonSearch_clicked ( bool checked = false );

private slots:
    void httpRequestFinished(int requestId, bool error);
    void readResponseHeader(const QHttpResponseHeader &responseHeader);
    void updateDataReadProgress(int bytesRead, int totalBytes);

};


class html
{
  private:
    QString data;

  public:
    html(const QString & data);
    ~html();
    void (*tag_func)(void * /*data*/, const QString &/*tag*/, const QString &/*context*/, int/*startpos*/);
    int get_ct(QString &out, const QString &html, const QString &tag, bool first_only, bool itags, const QString &cmp_name, const QString &cmp, int index = -1);
    static QString tag_params(const QString &tag, const QString &param, const QString &buffer, bool&close, QString & this_tag);
    static QString strip_tags(const QString &html);
};


#endif
